#!/bin/bash
set -e

if [[ -z "${JIANMU_URL}" ]]
then
  echo "[ERROR] The necessary url configuration is missing"
  exit 1
fi

URL="${JIANMU_URL}"
TIMEOUT=${JIANMU_TIMEOUT}
echo $URL
echo $TIMEOUT
HTTP_CODE=$(curl -m 10 --connect-timeout $TIMEOUT -s -X POST $URL -H "Content-Type: application/json" -d '{"def_agent_code_scc": "91510000X216000564", "manual_no": "Z79002542869", "user": "aeo"}' | grep -oP '"code":\s*\K\d+') || HTTP_CODE="ERROR"

echo -e "{
     "\"status_code\"" ":" "\"${HTTP_CODE}\""
}" > /usr/resultFile

echo "resultFile:"
cat /usr/resultFile